using System;
using System.Collections.Generic;

namespace DataAccess.Services
{
	public abstract class LookupEntity<TKey, TValue>
	{
		private static readonly IDictionary<TKey, TValue> memory = new Dictionary<TKey, TValue>();
		private readonly Func<TKey, TValue> lookup;

		protected LookupEntity(Func<TKey, TValue> lookup)
		{
			this.lookup = lookup;
		}

		protected TValue Get(TKey name)
		{
			if (!memory.ContainsKey(name))
			{
				memory[name] = lookup(name);
			}

			return memory[name];
		}
	}
}